package com.neusoft.crm.service.impl;


import com.baomidou.mybatisplus.core.injector.methods.SelectPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neusoft.crm.entity.Product;
import com.neusoft.crm.mapper.ProductMapper;
import com.neusoft.crm.service.IProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neusoft.crm.tools.CommonResult;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lplpok
 * @since 2023-06-19
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {

//    @Override
//    public CommonResult get_Product_Data(Integer currentPage, Integer pageSize) {
//        int offset = (currentPage - 1) * pageSize;
//        List<Product> productList = this.baseMapper.get_Product_Data(offset, pageSize);
//        CommonResult result = new CommonResult();
//        result.setStatusCode(200);
//        result.setResult(productList);
//        return result;
//    }

    @Override
    public CommonResult getPageList(String currentPage, String pagesize) {

        //sql
        int index = (Integer.valueOf(currentPage)-1)*Integer.valueOf(pagesize);


        List<Product> list = this.baseMapper.getPageList(index,Integer.valueOf(pagesize));
        long count = count();





        if(list == null || list.size() == 0){
            return new CommonResult(null ,204);
        }
        HashMap<String, Object> map = new HashMap<>();
        map.put("current",Integer.valueOf(currentPage));
        map.put("size",Integer.valueOf(pagesize));
        map.put("total",count());
        map.put("records",list);
        return new CommonResult<>(map);
    }
}
